package com.zwq.springbootlearn.controller;

import com.zwq.springbootlearn.properties.GirlProperties;
import com.zwq.springbootlearn.service.GirlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: zwq
 * Create in 2018/6/28 22:00
 */
//
@RestController //SPring 等同于@Controller 和@Responsebody的组合
public class HelloController {

/*    //把yml配置文件中配置的cupSize获取过来
    @Value("${cupSize}")
    private String cupSize;

    @Value("${age}")
    private Integer age;

    @Value("${content}")
    private String content;*/

    @Autowired
    private GirlProperties girlProperties;

    @Autowired
    private GirlService girlService;

    //value可写多个值，对应多个路径, 如果不写明method，则默认GET和POST都可以，但不推荐
    @RequestMapping(value = {"/hello2","/hi"}, method = RequestMethod.GET)
    public String say(){
        //System.out.println(content);
        System.out.println(girlProperties.getCupSize());

        return "Hello Spring Boot!";//+cupSize+age;
    }

    //组合注解&参数传递
    @GetMapping("/hello") //等同于@RequestMapping(value="/hello",method=RequestMethod.GET)
    public String say2(@RequestParam(value="id",required = false, defaultValue = "0") Integer id){

        return "Hello Spring Boot!" + id;
    }

    //测试事务管理
    @GetMapping("/girl/trans")
    public void girlTwo(){
        girlService.insertTwo();
    }
}
